Skip to content

Fix deserializing a null smart pointer not clearing the target - #8181

Merged
hkaiser merged 1 commit into
TheHPXProject:masterfrom
Vaatsal-source:fix/serialization-null-pointer-load
Nov 22, 2026
Merged

hkaiser merged 1 commit into
TheHPXProject:masterfrom
Vaatsal-source:fix/serialization-null-pointer-load

Conversation

@Vaatsal-source

Copy link
Copy Markdown
Contributor

Fixes #8179

Proposed Changes

  • serialize_pointer_tracked (input archive): reset the target (ptr.reset()) when the archived pointer is null, instead of leaving the old value in place.
  • serialize_pointer_untracked (input archive): assign Pointer(nullptr) in the null case. This also covers raw_ptr_type, which has no reset().
  • Add test_shared_null_clears_target and test_unique_null_clears_target to serialization_smart_ptr.cpp.

Any background context you want to provide?

Both load functions read the valid flag and only acted if (valid). Loading a null pointer into a target that already held a value therefore did nothing and the stale value survived. This is the same class of bug as the earlier list/deque fix (load must replace the existing content).

Both new tests fail without the change and pass with it. The serialization unit tests pass.

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Deserializing a null smart pointer now clears an existing value, rather than leaving the previous value intact. This applies to both tracked and untracked pointers.
    • Added coverage for this behavior with shared and unique pointers, confirming that deserializing a null value clears a non-null target.

When a serialized pointer is null, tracked and untracked deserialization now clear the destination. Tests verify this behavior for non-null std::shared_ptr<int> and std::unique_ptr<int> targets.

Changes: Null pointer deserialization

Layer / File(s) Summary
Clear targets for null pointers
libs/core/serialization/include/hpx/serialization/detail/pointer.hpp, libs/core/serialization/tests/unit/serialization_smart_ptr.cpp
Tracked deserialization resets the destination when the validity flag is false. Untracked deserialization assigns a null pointer. Tests verify that loading null shared and unique pointers clears non-null targets.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: Minimal · up to c5848

Deserializing a null pointer now leaves the target null, as the linked issue requests. Tests cover shared and unique pointers. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: deserializing a null smart pointer now clears the existing target. The raw summary and objectives confirm the change resets the target in the input-archive pointer de…
Description check Passed The description explains the change. It names the two modified load functions, serialize_pointer_tracked and serialize_pointer_untracked, and the new tests. It also gives the root cause, where the cod…
Linked Issues check Passed [#8179] requires that loading a serialized null smart pointer from an input_archive leaves the existing target null, for std::shared_ptr (tracked path) and std::unique_ptr (untracked path). Diff from …
Out of Scope Changes check Passed The whole-PR diff from merge base 3af219b to head c584889 changes two files: libs/core/serialization/include/hpx/serialization/detail/pointer.hpp and libs/core/serialization/tests/unit/serializa…
Full details: Title check

Explanation

The title states the main change: deserializing a null smart pointer now clears the existing target. The raw summary and objectives confirm the change resets the target in the input-archive pointer deserialization paths, so the title matches the changeset.

Full details: Description check

Explanation

The description explains the change. It names the two modified load functions, serialize_pointer_tracked and serialize_pointer_untracked, and the new tests. It also gives the root cause, where the code acted only when the valid flag was set, and links issue #8179.

Full details: Linked Issues check

Explanation

[#8179] requires that loading a serialized null smart pointer from an input_archive leaves the existing target null, for std::shared_ptr (tracked path) and std::unique_ptr (untracked path). Diff from merge base 3af219b to head c584889 for pointer.hpp adds an else branch to serialize_pointer_tracked (ptr.reset()) and to serialize_pointer_untracked (ptr = Pointer(nullptr)). The valid-true paths are unchanged. The untracked assignment also covers raw_ptr_type, which has no reset(). The diff for serialization_smart_ptr.cpp adds test_shared_null_clears_target and test_unique_null_clears_target. Each test serializes a null pointer, loads it into a non-null target, and checks HPX_TEST(!target). Both tests are called from main. The author reports that both tests fail without the change and pass with it. I did not build or run them. The issue requires no non-coding work.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff from merge base 3af219b to head c584889 changes two files: libs/core/serialization/include/hpx/serialization/detail/pointer.hpp and libs/core/serialization/tests/unit/serialization_smart_ptr.cpp. The header hunks are the two else branches required by #8179. The test hunks add two regression tests for the same null-into-non-null case for shared_ptr and unique_ptr. The changes since the previous reviewed head (980335e) are consistent with this scope. No unrelated changes appear in the reviewed evidence.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d2e4c4b-feef-4d91-8dee-1b0d2e9e6caf
Commits

Reviewing files that changed from the base of the PR and between 980335e and c584889.

Files selected for processing: 2

  • libs/core/serialization/include/hpx/serialization/detail/pointer.hpp
  • libs/core/serialization/tests/unit/serialization_smart_ptr.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@hkaiser hkaiser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fix is right. It conflicts with master now in serialization_smart_ptr.cpp (tests added there by #8144), could you please rebase? Then this is good to go.

serialize_pointer_tracked and serialize_pointer_untracked only acted when the archived pointer was valid, so loading a null pointer into a target that already held a value left that value in place. Reset the target in the null case and add tests for std::shared_ptr and std::unique_ptr.

Fixes TheHPXProject#8179

Signed-off-by: Vaatsalya Srivastava <vaatsalyasrivastava_ee_25a19036@dtu.ac.in>
@Vaatsal-source
Vaatsal-source force-pushed the fix/serialization-null-pointer-load branch from 980335e to c584889 Compare November 21, 2026 21:24
@Vaatsal-source

Copy link
Copy Markdown
Contributor Author

Thanks, Rebased on master and resolved the conflict in serialization_smart_ptr.cpp; the new tests from #8144 and mine are both kept. Please note that master currently fails to build in preprocess_keep_alive.cpp / post_receive_actions.cpp (extra_data_id_type is now numeric); #8188 fixes that, so CI here should go green once it lands. I also verified locally with #8188 applied: serialization_smart_ptr_test passes.

@hkaiser hkaiser left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rebase, LGTM.

@hkaiser
hkaiser merged commit 7b3a3f0 into TheHPXProject:master Nov 22, 2026
156 of 158 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deserializing a null shared_ptr/unique_ptr does not clear the existing target

2 participants